package com.lanou.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by lizhongren1.
 */
public class StrUtils {

    public static boolean isNull(String str) {

        if (str == null || str.length() == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isMailRight(String str) {

        return regTest(str, 1);
    }

    public static boolean isPhoneNumberRight(String str) {
        return regTest(str, 0);
    }

    private static boolean regTest(String str, Integer regType) {
        String regEx = "";
        if (regType == 1) {
            regEx = "[0-9a-zA-Z_]{1,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
        } else {
            regEx = "^1[3|4|5|8][0-9]\\d{8}$";
        }
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }


}
